package ktx.test.collection

import androidx.collection.arraySetOf
import com.helloandroid.ext.Json
import com.helloandroid.tools.MyTimeUtils
import org.junit.Test
import java.util.*
import kotlin.collections.ArrayList

class TestCollection {

    @Test
    fun test_arraySet(){
        val combinedArraySet = arraySetOf<Int>(1,2,3) + arraySetOf<Int>(3,4,5)
        combinedArraySet.forEach(::println)
    }

    @Test
    fun test_treeMap(){
        val StepMap: TreeMap<Int, Int> = TreeMap(mapOf<Int, Int>(
                12000 to 100,
                14000 to 100,
                16000 to 100,
                18000 to 100,
                20000 to 100,
                22000 to 100,
                24000 to 100,
                26000 to 100,
                28000 to 100,
                30000 to 100,
                2500 to 30,
                1500 to 45,
                3000 to 60,
                4500 to 80,
                6000 to 100,
                8000 to 100,
                10000 to 100
        ))

        for((k,v) in StepMap){
            println("k:$k,v:$v")
        }
    }

    @Test
    fun testForeEach(){
        val list = listOf<Int>(1,2,3,4,5,6,7)
        val bs = 4
        var targetIdx = -1
        list.forEachIndexed { index, num ->
            if(bs < num){
                return@forEachIndexed
            }
            println("num is : $num")
            targetIdx = index
        }
        println("=============================")
        println("targetIdx:$targetIdx")
    }

    @Test
    fun testArr(){
        val lst = generateSequence(5){it + 1}.takeWhile { it < 10 }.toList()
        println("lst:$lst")
        val arr = Array(lst.size){
            println("it:$it")
            lst[it] * 2
        }
        println("=========================")
        arr.forEach {
            println(it)
        }
    }

    @Test
    fun null_toString(){
        println(null.toString())
    }

    @Test
    fun parseTime(){
        val str = """
            2021-02-22T19:35:41.000Z
        """.trimIndent()
        val stamp = MyTimeUtils.transformTimeByZone(str)
        println("stamp:$stamp")
        println("daytime:${MyTimeUtils.fullString(stamp)}")
    }

    @Test
    fun test_jsonstr(){
        val json = Json{
            "name" to "zhangsan"
            "age" to 12
        }
        println(json)
    }

    @Test
    fun test_true(){
        val str = "false"
        println(str.toBoolean() == false)
    }
}